﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="insertGrade.aspx.cs" Inherits="Teacher_insertGrade" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">

        .style1
        {
            font-family: 微軟正黑體;
            font-size: xx-large;
        }
        .style2
        {
            text-align: center;
        }
        .style3
        {
            width: 82%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="style2">
    
        <span class="style1">新增學生成績</span><br />
        <br />
        <table align="center" class="style3">
            <tr>
                <td colspan="2">
                    目前身分：<asp:Label ID="Label1" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;</td>
            </tr>
            <tr>
                <td colspan="2">
                    請選擇課程：<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
                        DataSourceID="SqlDataSource1" DataTextField="CourseName" 
                        DataValueField="CourseId" 
                        onselectedindexchanged="DropDownList1_SelectedIndexChanged">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    &nbsp;</td>
            </tr>
            <tr>
                <td rowspan="3">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                        CellPadding="4" DataSourceID="SqlDataSource2" ForeColor="#333333" 
                        GridLines="None" onselectedindexchanged="GridView1_SelectedIndexChanged" 
                        Width="330px">
                        <AlternatingRowStyle BackColor="White" />
                        <Columns>
                            <asp:BoundField DataField="StudentId" HeaderText="StudentId" 
                                SortExpression="StudentId" />
                            <asp:BoundField DataField="StudentName" HeaderText="StudentName" 
                                SortExpression="StudentName" />
                            <asp:BoundField DataField="Grade" HeaderText="Grade" SortExpression="Grade" />
                            <asp:CommandField ButtonType="Button" ShowSelectButton="True" />
                        </Columns>
                        <EditRowStyle BackColor="#2461BF" />
                        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                        <RowStyle BackColor="#EFF3FB" />
                        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                        <SortedAscendingCellStyle BackColor="#F5F7FB" />
                        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                        <SortedDescendingCellStyle BackColor="#E9EBEF" />
                        <SortedDescendingHeaderStyle BackColor="#4870BE" />
                    </asp:GridView>
                </td>
                <td>
                    目前選擇學生：<asp:Label ID="Label2" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    輸入成績：<asp:TextBox ID="TextBox1" runat="server" ValidationGroup="phone"></asp:TextBox>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                        ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator" 
                        ValidationExpression="^[0-9]{1,20}$" style="color: #FF0000" 
                        ValidationGroup="phone">僅限數字</asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="新增" 
                        ValidationGroup="phone" />
                </td>
            </tr>
        </table>
        <br />
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
            SelectCommand="SELECT Teaching.TeacherId, Teaching.CourseId, Teaching.serial, Course.CourseName FROM Teaching INNER JOIN Course ON Teaching.CourseId = Course.CourseId WHERE (Teaching.TeacherId = @TeacherId)">
            <SelectParameters>
                <asp:ControlParameter ControlID="Label1" Name="TeacherId" PropertyName="Text" 
                    Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
            SelectCommand="SELECT CourseTaken.StudentId, CourseTaken.CourseId, CourseTaken.Grade, Student.StudentName FROM CourseTaken INNER JOIN Student ON CourseTaken.StudentId = Student.StudentId WHERE (CourseTaken.CourseId = @CourseId)">
            <SelectParameters>
                <asp:ControlParameter ControlID="DropDownList1" Name="CourseId" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SqlDataSource3" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ProjectConnectionString %>" 
            SelectCommand="SELECT * FROM [CourseTaken] WHERE ([StudentId] = @StudentId)" 
            UpdateCommand="UPDATE [CourseTaken] SET [Grade] = @Grade WHERE [CourseId] = @CourseId AND [StudentId] = @StudentId">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="StudentId" 
                    PropertyName="SelectedRow.Cells[0].Text" Type="Int32" />
            </SelectParameters>
            <UpdateParameters>
                <asp:ControlParameter ControlID="TextBox1" Name="Grade" PropertyName="Text" 
                    Type="Int32" />
                <asp:ControlParameter ControlID="DropDownList1" Name="CourseId" 
                    PropertyName="SelectedValue" Type="Int32" />
                <asp:ControlParameter ControlID="GridView1" Name="StudentId" 
                    PropertyName="SelectedRow.Cells[0].Text" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    
    </div>
    </form>
</body>
</html>
